package com.ydx.Controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ydx.entity.Patrol;

import com.ydx.entity.PatrolAndShiyanshi;
import com.ydx.entity.Shiyanshi;
import com.ydx.service.PatrolService;

import com.ydx.util.JsonResponse3;

import com.ydx.util.ResponseData3;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/Patrol")
public class PatrolController {

    @Autowired
    private PatrolService patrolService;
    @GetMapping("/PatrolList")
    public JsonResponse3 listPatrol() {
        List<PatrolAndShiyanshi> patrols = patrolService.selectMore();
        System.out.println("来到了巡查表查询");

        // 构建自定义的响应数据格式
        JsonResponse3 response = new JsonResponse3();
        response.setCode(200);
        response.setMessage("成功!");
        ResponseData3 result = new ResponseData3();
        result.setTotal(patrols.size());
        result.setList(patrols);
        response.setResult(result);
        return response;
    }

    @GetMapping("/PatrolList2")
    public JsonResponse3 listPatrol2( @RequestParam String door ,@RequestParam String device ) {
        List<PatrolAndShiyanshi> patrols = patrolService.selectMore2(device,door);
        System.out.println("来到了巡查表查询");

        // 构建自定义的响应数据格式
        JsonResponse3 response = new JsonResponse3();
        response.setCode(200);
        response.setMessage("成功!");
        ResponseData3 result = new ResponseData3();
        result.setTotal(patrols.size());
        result.setList(patrols);
        response.setResult(result);
        return response;
    }

    @GetMapping("/PatrolList3")
    public JsonResponse3 listPatrol2( @RequestParam String door ,@RequestParam String device,@RequestParam int userid ) {
        List<PatrolAndShiyanshi> patrols = patrolService.selectMore3(device,door,userid);
        System.out.println("来到了巡查表查询");

        // 构建自定义的响应数据格式
        JsonResponse3 response = new JsonResponse3();
        response.setCode(200);
        response.setMessage("成功!");
        ResponseData3 result = new ResponseData3();
        result.setTotal(patrols.size());
        result.setList(patrols);
        response.setResult(result);
        return response;
    }

    @GetMapping("/WodePatrolList/{userid}")
    public JsonResponse3 WodelistPatrol(@PathVariable int userid) {
        List<PatrolAndShiyanshi> patrols =  patrolService.selectWodePatrol(userid);
        // 构建自定义的响应数据格式
        JsonResponse3 response = new JsonResponse3();
        response.setCode(200);
        response.setMessage("成功!");
        ResponseData3 result = new ResponseData3();
        result.setTotal(patrols.size());
        result.setList(patrols);
        response.setResult(result);
        return response;
    }


    @DeleteMapping("/DeletePatrol/{patrolid}")
    public boolean DeletePatrol(@PathVariable int patrolid) {
        System.out.println("删除");
        return patrolService.deletepatrol(patrolid);
    }

    @PutMapping("/AddPatrol")
    public boolean AddPatrol(@RequestBody  Patrol patrol) {
        System.out.println(patrol);
        System.out.println("新增");
        Date now = new Date();
        patrol.setCreattime(now);
        return patrolService.saveNew(patrol);
    }

    @PostMapping("/UpdatePatrol")
    public boolean UpdateNewPatrol( @RequestBody Patrol patrol) {
        Date now = new Date();
        patrol.setCreattime(now);
        System.out.println("__________________");
        System.out.println("patrol:"+patrol);
        return patrolService.UpdateNewPatrol(patrol);
    }
}
